cucDefine(['common', 'title/title3'], function(common, TitleJH3){
    let {loadStyle, copyText, commonInit, commonVar} = common;
    class QIO extends HTMLElement {
        constructor() {
            super();
            let shadow = this.attachShadow({mode: 'open'});
            loadStyle(shadow, commonVar.rootPath + "/assets/component/questionio/qio.css")
            let div = document.createElement('div');
            commonInit(this, div);
            div.className = 'jh-qio';
            this.addI(div);
            this.addO(div);
            shadow.appendChild(div);
            // this.onMounted();
        }
        addI(dom) {
            let div = document.createElement("div");
            let headI = new TitleJH3("输入", false);
            let BlockI = document.createElement("blockquote");
            BlockI.className = 'jh-block';
            BlockI.innerText = this.getAttribute("in");
            let ai = document.createElement("a");
            ai.onclick = this.clip(ai, BlockI);
            ai.innerText = "复制";
            div.appendChild(headI);
            div.appendChild(ai);
            div.append(BlockI);
            dom.append(div);
        }
        addO(dom) {
            let div = document.createElement("div");
            let headO = new TitleJH3("输出", false);
            let BlockO = document.createElement("blockquote");
            BlockO.className = 'jh-block';
            BlockO.innerText = this.getAttribute("out");
            let ao = document.createElement("a");
            ao.onclick = this.clip(ao, BlockO);
            ao.innerText = "复制";
            div.appendChild(headO);
            div.appendChild(ao);
            div.append(BlockO);
            dom.append(div);
        }
        clip(dom, textdom) {
            return ()=>{
                copyText(textdom.innerText, {
                    success: ()=>{
                        dom.innerText = "复制成功";
                        setTimeout(()=>{
                            dom.innerText = "复制";
                        },1000);
                    },
                    fail: ()=>{
                        dom.innerText = "复制失败";
                        setTimeout(()=>{
                            dom.innerText = "复制";
                        },1000);
                    }
                });
            }
        }
    }
    return QIO;
});